package cn.com.scitc.dao;

import cn.com.scitc.db.MyBatisHelper;
import cn.com.scitc.mapper.PaidMapper;
import cn.com.scitc.mapper.UserMapper;
import cn.com.scitc.model.Paid;
import cn.com.scitc.model.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class PaidDao {
    public Paid findById(Integer id) {
        try (SqlSession session = MyBatisHelper.getSessionFactory().openSession()) {
            PaidMapper mapper = session.getMapper(PaidMapper.class);
            return mapper.selectByPrimaryKey(id);
        }
    }

    public List<Paid> findAll() {
        try (SqlSession session = MyBatisHelper.getSessionFactory().openSession()) {
            PaidMapper mapper = session.getMapper(PaidMapper.class);
            return mapper.selectAll();
        }
    }

    public int insert(Paid paid) {
        try (SqlSession session = MyBatisHelper.getSessionFactory().openSession()) {
            PaidMapper mapper = session.getMapper(PaidMapper.class);
            int result = mapper.insert(paid);
            session.commit();
            return result;
        }
    }

    public void update(Paid paid) {
        try (SqlSession session = MyBatisHelper.getSessionFactory().openSession()) {
            PaidMapper mapper = session.getMapper(PaidMapper.class);
            int result = mapper.updateByPrimaryKey(paid);
            session.commit();
        }
    }
}
